import httpRequest from './hrequest'
const Request = new httpRequest()

// 请求拦截器
Request.interceptors.request((request: any) => {
 /* 
  if (request.header["content-type"]) {
    request.header['content-type'] = request.header.contentType
    delete request.header["content-type"]
	console.log('删除contentType:',request.header)
  } */
  /* if (request.method === 'POST') {
	  request.header.token=uni.getStorageSync('token');  //请求前带上token
  } */
  
  if (request.method === 'GET') {
    //request.data = JSON.stringify(request.data)
	//delete request.header.token;
	let reqData=JSON.stringify(request.data)
	if((reqData!="{}")){
		request.url = request.url + '?' +reqData
	}
  }
  return request
})

// 响应拦截器
Request.interceptors.response((response: any) => {
  //const token = uni.getStorageSync('token')
  // if (response.data.code === 403) {
  //   uni.showToast({
  //     title: token ? '请重新登录' : '请先登录',
  //     icon: 'none',
  //     duration: 2000,
  //   })
  //   uni.removeStorageSync('token')
  //   uni.removeStorageSync('userInfo')
  // }
  return response
})



// 设置默认配置
Request.setConfig((config: any) => {
  /* config.baseURL = "" //https://www.qq.com
  config.header.contentType="application/json;charset=utf-8";
  config.header.Authorization=uni.getStorageSync('token'); */
  /* 
	  if (uni.getStorageSync('token')) {
		config.header['Authorization'] = 'Bearer ' + uni.getStorageSync('token')
	  } 
  */
  return config
})

export default Request